package com.gd.luxiaoyu.moduels.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gd.luxiaoyu.Constant;
import com.gd.luxiaoyu.moduels.entity.ReviewTableEntity;
import com.gd.luxiaoyu.moduels.service.ReviewTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("right/reviewtable")
public class ReviewTableController {
    @Autowired
    private ReviewTableService reviewTableService;
    Constant constant =new Constant();
    /**
     * 查看所有的评论列表
     */
   @RequestMapping("/list")
    @ResponseBody
    public Map<String,Object> list(Page<ReviewTableEntity> reviewTableEntityPage,ReviewTableEntity reviewTableEntity){
        IPage<ReviewTableEntity> page =  reviewTableService.geteReview(reviewTableEntityPage,reviewTableEntity);
        Map<String,Object> map = new HashMap<>();
        map.put("toals",page.getTotal());
        map.put("rows",page.getRecords());
        return map;
    }
    /*
    * 插入评论的内容
    * */
    @RequestMapping("/insert")
    @ResponseBody
    public R<?> insert(ReviewTableEntity reviewTableEntity){
        boolean insert = reviewTableService.save(reviewTableEntity);
        return insert ? R.ok(constant.SUCCESSFUL) : R.failed(constant.FAIL);
    }

    /*
     * 通过评论的id删除评论
     * */
    @RequestMapping("/deleteID")
    @ResponseBody
    public R<?> deleteID(ReviewTableEntity reviewTableEntity){
        boolean delete = reviewTableService.removeById(reviewTableEntity.getId());
        return  delete ? R.ok(constant.SUCCESSFUL) : R.failed(constant.FAIL);
    }

    /*
     * 通过评论的APP的id删除评论
     * */
    @RequestMapping("/deleteAid")
    @ResponseBody
    public R<?> deleteAid(ReviewTableEntity reviewTableEntity){
        boolean delete = reviewTableService.removeById(reviewTableEntity.getAid());
        return  delete ? R.ok(constant.SUCCESSFUL) : R.failed(constant.FAIL);
    }
    /*
     * 通过评论的用户的id删除评论
     * */
    @RequestMapping("/deleteUid")
    @ResponseBody
    public R<?> deleteUid(ReviewTableEntity reviewTableEntity){
        boolean delete = reviewTableService.removeById(reviewTableEntity.getUid());
        return  delete ? R.ok(constant.SUCCESSFUL) : R.failed(constant.FAIL);
    }

}
